package cn.edu.neusoft.wuguangsheng.flowerimpression.fragment;


import android.app.Fragment;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.EmptyRecyclerView;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.GoodAdapter;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.GoodsBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.ListListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.GetCollectionGoodsListModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class ShopShouCGoodsFragment extends BaseFragment {
    EmptyRecyclerView shoucanggoods_rv;
    private List<GoodsBean> items;
    boolean up = false;
    private View mEmptyView;
    TextView tv_message;
    @Override
    void initView() {
        shoucanggoods_rv = (EmptyRecyclerView)view.findViewById(R.id.shoucanggoods_rv);
        mEmptyView = (View)view.findViewById(R.id.id_empty_scgoods);
        tv_message = (TextView)view.findViewById(R.id.tv_message);

        GetCollectionGoodsListModel getCollectionGoodsListModel = new GetCollectionGoodsListModel();
        getCollectionGoodsListModel.getCollectionGoodsList(getid(),goodsBeanListListener);

    }

    @Override
    void initEvent() {

    }

    @Override
    void initDate() {

    }

    public ShopShouCGoodsFragment() {
        // Required empty public constructor
    }
    ListListener<GoodsBean> goodsBeanListListener = new ListListener<GoodsBean>() {
        @Override
        public void onResponse(List<GoodsBean> list) {
            LinearLayoutManager linearLayoutManager=new LinearLayoutManager(getContext());
            linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            shoucanggoods_rv.setLayoutManager(linearLayoutManager);
            items=list;
            GoodAdapter goodAdapter=new GoodAdapter(getContext(),items,R.layout.goods_item);
            shoucanggoods_rv.setAdapter(goodAdapter);
            shoucanggoods_rv.setItemAnimator(new DefaultItemAnimator());
            shoucanggoods_rv.setEmptyView(mEmptyView);
            tv_message.setText("快去收藏喜欢的商品吧！");
        }

        @Override
        public void onFail(String msg) {

        }
    };


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        setLayout_file(R.layout.fragment_shop_shou_cgoods);
        return super.onCreateView(inflater,container,savedInstanceState);
    }
    @Override
    public void onPause() {
        super.onPause();
        up = true;
    }

    @Override
    public void onResume() {
        super.onResume();
        if (up) {
            initView();
            initEvent();
            initDate();
            up = false;
        }
    }

}
